// pages/book-lab/book-lab.js
Page({
  data: {
    searchKeyword: '',
    labs: [
      { title: '计算机实验室一', image: '/image/1.jpg', manager: '张老师', address: '知行楼A102', number: '30人'},
      { title: '生物实验室二', image: '/image/1.jpg', manager: '李老师', address: '知行楼A205', number: '30人'},
      { title: '物理实验室一', image: '/image/1.jpg', manager: '王老师', address: '知行楼A301', number: '30人'},
      { title: '计算机实验室二', image: '/image/1.jpg', manager: '赵老师', address: '知行楼B401', number: '30人'},
      { title: '计算机实验室三', image: '/image/1.jpg', manager: '刘老师', address: '知行楼A303', number: '30人'}
    ],
    filteredLabs: []
  },

  onLoad() {
    // 初始化显示所有实验室
    this.setData({
      filteredLabs: this.data.labs
    });
  },

  // 输入时实时搜索
  onInput(e) {
    const keyword = e.detail;
    this.setData({
      searchKeyword: keyword
    });
    this.filterLabs(keyword);
  },

  // 点击搜索按钮
  onSearch(e) {
    const keyword = e.detail;
    this.filterLabs(keyword);
  },

  // 清空搜索
  onClear() {
    this.setData({
      searchKeyword: '',
      filteredLabs: this.data.labs
    });
  },

  // 过滤实验室
  filterLabs(keyword) {
    const filtered = this.data.labs.filter(lab => 
      lab.title.toLowerCase().includes(keyword.toLowerCase())
    );
    this.setData({
      filteredLabs: filtered
    });
  },

  onClick(e) {
    const labId = e.currentTarget.dataset.id;
    
    // 显示预约提示（测试用，正式使用时可以移除）
    wx.showToast({
      title: `预约${labId}实验室`,
      icon: 'success',
      duration: 1500
    });
    
    // 跳转到实验室详情页
    wx.navigateTo({
      url: `/pages/lab/lab?labId=${labId}`
    });
  },
  onRepairClick: function(e) {
    const labId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/feedback/feedback?labId=${labId}`
    });
  },
  ondetailClick: function(e) {
    const labId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/detail/detail?labId=${labId}`
    });
  }
});